import pymysql
class DB:

    def __init__(self) -> None:
        # 主库写于导入
        self.conn = pymysql.connect(host='localhost', port=3306, user='root', password='011011', db="h2205a_syl", cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()

    # 更新添加
    def update(self, sql):
        self.cursor.execute(sql)
        self.conn.commit()
        return self.cursor.lastrowid

    # 获取一条
    def findOne(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchone()
        return res

    # 获取多条
    def findAll(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res

    # 提交方法
    def commit(self):
        self.conn.commit()

    # 回滚方法
    def rollback(self):
        self.conn.rollback()

db = DB()

